package com.example.easy.excel.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {


    @Value("${api.doc.group-name}")
    private String groupName;

    @Value("${api.doc.host}")
    private String host;

    @Value("${api.doc.title}")
    private String title;

    @Value("${api.doc.description}")
    private String description;

    @Value("${api.doc.name}")
    private String name;

    @Value("${api.doc.url}")
    private String url;

    @Value("${api.doc.email}")
    private String email;

    @Value("${api.doc.basePackage}")
    private String basePackage;


    @Value("${api.doc.version}")
    private String version;


    @Value("${api.doc.termsOfServiceUrl}")
    private String termsOfServiceUrl;



    @Bean
    public Docket docket() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .host(host)
                .apiInfo(apiInfo())
                .groupName(groupName)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .termsOfServiceUrl(termsOfServiceUrl)
                .contact(new Contact(name,url,email))
                .version(version)
                .build();
    }
}